package ac.snu.street;

import java.net.ServerSocket;
import java.net.Socket;

public class StreetPostServer {
	private static final int PORT = 4444;

	public static void main(String[] args) {
		StreetDB database = null;
		try {
			System.out.println("S: Connecting..."); // debug
			ServerSocket serverSocket = new ServerSocket(PORT);
			database = new StreetDB();
			
			try {
				while (true) {
					System.out.println("S: Wating for client..."); // debug
					Socket client = serverSocket.accept();
	
					Thread subServerThread = new Thread(new TCPServer(client, database));
					subServerThread.start();
				}
			} catch (Exception e) {
				System.out.println("S: Error"); // debug
				e.printStackTrace();
			} finally {
				if (database != null) {
					database.close();
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
